<template>
	<view class="page-body ">
		<web-view :src="html" :webview-styles="webviewStyles" v-if="hasHtml" @message="handleMessage"></web-view>
		
	</view>
</template>

<script>
	var that;
	import {Pages,TimeStorage} from '@/utils/utils.js';
	import {host} from '@/utils/Config.js';
	var wv;
	export default{
		data(){
			return{
				isNextStep:false,
				newpwd:"",
				oldpwd:"",
				isnewpwd:false,
				isoldpwd:false,
				inputType1:"password",
				inputType2:"password",
				code:"",
				token:"",
				randomData:"",
				html:"",
				hasHtml:false,
				webviewStyles:{
					progress:{
						 color: '#FF3333'
					}
				}
			}
		},
		onLoad(options){
			// #ifdef APP-PLUS
			plus.nativeUI.showWaiting();
			// #endif
			that=this;
			if(options.token){
				this.token = options.token;
				this.code = options.textcode;
				// #ifdef APP-PLUS
				plus.storage.setItem('token',options.token);
				plus.storage.setItem('code',options.textcode);
				plus.storage.setItem('utoken',TimeStorage.geted('utoken'))
				// #endif
			}
			that.html = `${host}/payword?textcode=${options.textcode}&token=${options.token}&utoken=${TimeStorage.geted('utoken')}`
			that.hasHtml = true;
		},
		onReady(){
			// #ifdef APP-PLUS
			plus.nativeUI.closeWaiting();
			// #endif
			// #ifdef APP-PLUS
			var currentWebview = this.$mp.page.$getAppWebview() //获取当前页面的webview对象
			setTimeout(function() {
				wv = currentWebview.children()[0];
				// wv.setCssText('#backURL{display:none;}')
			}, 1000); //如果是页面初始化调用时，需要延时一下
			// #endif
		},
		onShow(options){
			
		},
		computed:{

		},
		methods:{
			handleMessage(e){
				uni.showModal({
					content: JSON.stringify(e.detail.data),
					showCancel: false
				});
				console.log(e.detail.data,'dfsfsdfds')
			},
			getRandom(){
				this.$https.POST({//修改登录密码
					url:'/pay/getRandom',
					data:{
					},
					success(res){
						that.randomData = res.data
					}
				})
			},
			nextStep(){
				let oldpwd=this.oldpwd;
				if(this.isNextStep){
					this.$https.POST({//修改登录密码
						url:'/pay/openacctVerifyIndividual',
						data:{
							password:that.oldpwd,
							verify_code:that.code,
							token:that.token
						},
						success(res){
							uni.showToast({
								title:res.message,
								icon:'none'
							})
							
						}
					})
				}else{
					if(oldpwd==""){
						this.$showToast('请输入旧密码')
						return false;
					}
					if(newpwd<8){
						this.$showToast('新密码请输入8~16位密码');
						return false
					}
					if(!checkword(newpwd)){
						this.$showToast('新密码须包含数字，字母，符号中至少2种元素');
						return false;
					}
				}
			},
			bindChange(e){
				let value=e.detail.value;
				this.isoldpwd=value.length>=6&&value.length<12;
				isSure(this.isoldpwd,this.isnewpwd,this)
				this.oldpwd=value;
			},
			iptChange(e){
				let value=e.detail.value;
				this.isnewpwd=checkword(value)
				isSure(this.isoldpwd,this.isnewpwd,this)
				if(value.length==12)return;
				this.newpwd=value;
			},
			showPwd(type){
				let inputType
				if(type==1){
					inputType='inputType1'
				}else if(type==2){
					inputType='inputType2'
				}
				if(this[inputType]=="password"){
					this[inputType]="text"
				}else{
					this[inputType]="password"
				}
			},
			
		},
		onBackPress(options) {
			uni.$emit('backpress')
		}
		
	}
	function isSure(v1,v2,that){
		if(v1==v2){
			that.isNextStep=true
		}else{
			that.isNextStep=false
		}
	}
	
	function checkword(value){
		var pwdreg=/(?!^(\d+|[a-zA-Z]+|[~!@#$%^&*()_+<>?:"{},.\/;'[\]]+)$)^[\w~!@#$%^&*()_+<>?:"{},.\/;'[\]]{8,16}$/;
		return pwdreg.test(value)
	}
</script>

<style lang="scss" scoped="">
	@import '../../../../static/css/user.css';
	page{background: #fff;}
	.mt70{margin-top: 70upx;}
	.tip-text{color: #4c4c4c;line-height: 80upx;font-size: 26upx;}
	.button{margin-top:40upx; }
</style>
